import QtQuick 1.0
import "../Delegates"
import "../WebAccess/TwitterAPI.js" as TwitterAPI
import "../WebAccess/PictureAPI.js" as PictureAPI
import "../Util/Util.js" as Util

//つぶやき系データ用
ListView {
    id: _root
    x: 0
    y: 0
    height: parent.height
    width: parent.width
    clip: true      //これをしないと下へスクロールする時にアクションバーに食い込む

    property bool loading: (count < 1)

    property bool more_new: contentY < 0  //上へ突き抜けた
    property bool more: (contentY + height) > contentHeight   //下へ突き抜けた


    delegate: Delegate{
        id: _delegate
        width: _root.width
        acceptedButtons: Qt.LeftButton | Qt.RightButton

        //itemIndex: _status_id
        itemId: makeItemId()
        itemTitle: makeItemTitle()
        itemMessage: makeItemMessage()
        itemInformation: makeItemInfomation()
        iconPath: _icon

        //保存用
        property string screenName: _screen_name        //Screen name
        property string inReplyToStatusId: _in_reply_to_status_id
        property string inReplyToScreenName: _in_reply_to_screen_name

        property variant urlList: null      //URLのリスト

        //IDを成形する
        function makeItemId(){
            return _status_id;
        }

        //タイトルを成形する
        function makeItemTitle(){
            return _screen_name + " / " + _name;
        }

        //本文を成形する
        function makeItemMessage(){
            var text = _text;

            //URLを正規表現で探す
            var re = new RegExp("http[s]*://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+", "g");
            var urls = _urls.match(re);
            //画像があれば指定する
            PictureAPI.getPcitureUrl(urls, this);
            //URLを保存
            urlList = urls;

            //記号を戻す
            text = Util.decodeHtmlSymbol(text) + "\n";

            //場所
            text += "Location : " + _location + "\n";
            text += "Bio : " + _bio;

            return text;
        }

        //情報を成形する
        function makeItemInfomation(){
            var ret = "";

            ret += "Friends : " + _friends_count
                    + " / Followers" + _followers_count;
            ret += "\nStatusCount : " + _statuses_count;
            if(_following === "true"){
                ret += "\nFollowing"
            }

            return ret;
        }

        onClicked: {
//            Util.outputDebugString("onClicked:" + prevPressedButtons
//                                   + ",index=" + currentIndex
//                                   + ",itemId=" + itemId);
            switch(itemIndex){
            case 0:
                break;
            case 1:
                break;
            case 2:
                break;
            default:
                break;
            }

            //マウス情報保存
            _selectItemInfo.mouse_x = mouse.x;
            _selectItemInfo.mouse_y = mouse.y + _delegate.y + _root.parent.y;
            //情報を一時保存
            //_selectItemInfo.itemId = itemId;
            _selectItemInfo.screenName = screenName;
            _selectItemInfo.message = _text;//itemMessage;

            //次の動作
            switch(prevPressedButtons){
            case Qt.LeftButton:
                break;
            case Qt.RightButton:
                //メニューを出す
                _menuContainer.state = "MenuContextUsers";
                break;
            default:
                break;
            }
        }

//        MouseArea {
//            anchors.fill: parent
//            acceptedButtons: Qt.LeftButton | Qt.RightButton
//        }
    }

    //読込中
    Image {
        anchors.centerIn: parent
        source: "../images/spinner.png"

        NumberAnimation on rotation {
            from: 0
            to: 360
            duration: 1500
            loops: Animation.Infinite
            running: loading
        }
        visible: loading
    }

}
